Skip to content

fix(ai-client): correlate synthesized resume terminals to request run - #1053

Open
harshlocham wants to merge 2 commits into
TanStack:mainfrom
harshlocham:fix/ai-client-synth-terminal-request-run-correlation
Open

fix(ai-client): correlate synthesized resume terminals to request run#1053
harshlocham wants to merge 2 commits into
TanStack:mainfrom
harshlocham:fix/ai-client-synth-terminal-request-run-correlation

Conversation

@harshlocham

@harshlocham harshlocham commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

When interrupt resume continuation streams omit a real RUN_FINISHED / RUN_ERROR, the connect wrapper synthesizes a terminal event. Those synthesized terminals were pushed without stamping the client request runId, so getChunkRunId() fell back to the provider continuation id. That left activeRunIds uncleared and sessionGenerating stuck true after Approve appeared to succeed.

This PR stamps synthesized terminals with runContext?.runId (same as real stream chunks), unskips the resume correlation unit tests, and adds a patch changeset for @tanstack/ai-client.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Improved interrupted conversation resumes so they complete reliably when terminal events are missing from provider responses.
    • Ensured synthesized success and error events are correctly associated with the originating request.
    • Improved handling of approval metadata during resumed interactions.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 031ff753-3e08-463e-838a-78998011539c

📥 Commits

Reviewing files that changed from the base of the PR and between 0802dcf and aa8cd10.

📒 Files selected for processing (1)
  • .changeset/jolly-ravens-start.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/jolly-ravens-start.md

📝 Walkthrough

Walkthrough

The connection wrapper assigns the caller request runId to synthesized RUN_FINISHED and RUN_ERROR events. Resume tests validate event correlation and asynchronous terminal states.

Changes

Resume run ID correlation

Layer / File(s) Summary
Synthetic terminal event correlation
packages/ai-client/src/connection-adapters.ts, .changeset/jolly-ravens-start.md
Synthetic RUN_FINISHED and RUN_ERROR events use the caller request runId. The changeset records the patch.
Resume correlation test coverage
packages/ai-client/tests/chat-client-resume.test.ts
Resume fixtures include approval metadata. Enabled tests validate synthesized success and error correlation and wait for terminal state conditions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • TanStack/ai#1034: Both PRs modify connection adapter run ID correlation for resume and terminal events.
  • TanStack/ai#1051: The PRs address resumable-stream and interrupt/resume behavior.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: correlating synthesized resume terminal events with the client request run ID.
Description check ✅ Passed The description explains the change and motivation, completes the checklist, and documents the release impact with a changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@harshlocham
harshlocham marked this pull request as ready for review August 4, 2026 17:20
Interrupt resume left sessionGenerating stuck when the provider
continuation omitted RUN_FINISHED/RUN_ERROR, because the connect
wrapper synthesized terminals without the client request run stamp.
@harshlocham
harshlocham force-pushed the fix/ai-client-synth-terminal-request-run-correlation branch from 2894bac to 0802dcf Compare August 5, 2026 06:30
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nx-cloud

nx-cloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit aa8cd10

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 23s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-05 09:57:33 UTC

@pkg-pr-new

pkg-pr-new Bot commented Aug 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@1053

@tanstack/ai-acp

npm i https://pkg.pr.new/@tanstack/ai-acp@1053

@tanstack/ai-angular

npm i https://pkg.pr.new/@tanstack/ai-angular@1053

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@1053

@tanstack/ai-bedrock

npm i https://pkg.pr.new/@tanstack/ai-bedrock@1053

@tanstack/ai-byteplus

npm i https://pkg.pr.new/@tanstack/ai-byteplus@1053

@tanstack/ai-claude-code

npm i https://pkg.pr.new/@tanstack/ai-claude-code@1053

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@1053

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@1053

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@1053

@tanstack/ai-codex

npm i https://pkg.pr.new/@tanstack/ai-codex@1053

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1053

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1053

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1053

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@1053

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@1053

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@1053

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@1053

@tanstack/ai-grok-build

npm i https://pkg.pr.new/@tanstack/ai-grok-build@1053

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@1053

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1053

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1053

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1053

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@1053

@tanstack/ai-memory

npm i https://pkg.pr.new/@tanstack/ai-memory@1053

@tanstack/ai-mistral

npm i https://pkg.pr.new/@tanstack/ai-mistral@1053

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@1053

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@1053

@tanstack/ai-opencode

npm i https://pkg.pr.new/@tanstack/ai-opencode@1053

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@1053

@tanstack/ai-persistence

npm i https://pkg.pr.new/@tanstack/ai-persistence@1053

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@1053

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@1053

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@1053

@tanstack/ai-sandbox

npm i https://pkg.pr.new/@tanstack/ai-sandbox@1053

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1053

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1053

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1053

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1053

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1053

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1053

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@1053

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1053

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@1053

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@1053

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@1053

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1053

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@1053

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1053

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1053

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1053

commit: aa8cd10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants